public class Test16 {
    public static void main(String[] args) {


        int[] arr = getCommonElements(new int[]{1,2,3,4,5}, new int[]{3,4,5,6,7});

        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
        }
    }

    public static int[] getCommonElements(int[] arr1, int[] arr2) {
        int len1 = arr1.length;
        int len2 = arr2.length;

        int[] arr = new int[len1 > len2 ? len2 : len1];

        int count = 0;

        for (int i = 0; i < len1; i++) {//arr1
            for (int j = 0; j < len2; j++) {//arr2
                if (arr1[i] == arr2[j]) {
                    arr[count] = arr1[i];
                    count++;
                }
            }
        }

        return arr;
    }
 }
